package net.khoroshev.wschat.service.auth;

import net.khoroshev.wschat.dao.DataStorageProvider;
import net.khoroshev.wschat.dao.JBDCProvider;
import net.khoroshev.wschat.model.entity.AuthUser;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.provisioning.UserDetailsManager;

/**
 * Created with IntelliJ IDEA.
 * User: vfirstov
 * Date: 01.12.13
 * Time: 23:24
 *
 */

public class AuthUserManager implements UserDetailsManager {

    private DataStorageProvider dataStorageProvider;

    public AuthUserManager(final DataStorageProvider dataStorageProvider) {
        this.dataStorageProvider = dataStorageProvider;
    }

    @Override
    public void createUser(final UserDetails user) {
        dataStorageProvider.createUser((AuthUser) user);
    }

    @Override
    public void updateUser(final UserDetails user) {
        dataStorageProvider.updateUser((AuthUser) user);
    }

    @Override
    public void deleteUser(final String username) {
        dataStorageProvider.deleteUser(username);
    }

    @Override
    public void changePassword(final String oldPassword, final String newPassword) {
        dataStorageProvider.changePassword(oldPassword, newPassword);
    }

    @Override
    public boolean userExists(final String username) {
        return dataStorageProvider.userExists(username);
    }

    @Override
    public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {
        return dataStorageProvider.loadUserByUsername(username);
    }

}
